/*
 * Alvin Baldemeca
 * 
 * TCSS 305 - Spring 2012
 * Tetris Project Part 1
 * 
 * This package contains the pieces needed for the tetris game being developed.
 * The classes are mutable, however there are some defensive copying employed in
 * the code.  The model package all so contains test for the tetris pieces. 
 */
package model;

import java.awt.Color;



/**
 * An abstract class represents Tetris game pieces that can be place on
 * a board and move left, right, down and rotate. 
 * @author Alvin Baldemeca
 * @version 4/19/2012
 */
public abstract class AbstractPiece implements Piece
{
  /**
   * The index at which the piece has not been rotated or its initial
   * rotation when the piece was created.  
   */
  public static final int NO_ROTATION = 0;
  
  /**
   * The index at which the piece has been rotated once. 
   */
  public static final int FIRST_ROTATION = 1;
  
  /**
   * The index at which the piece has been rotated twice. 
   */
  public static final int SECOND_ROTATION = 2;
  
  /**
   * The index at which the piece has been rotated thrice. 
   */
  public static final int THIRD_ROTATION = 3;
  
  /**
   * The rotational state of the piece represented by the vector.
   */
  protected final int[][] my_rotation;
  
  /**
   * The x coordinate of the piece from its lower left corner. 
   */
  private int my_x;
  
  /**
   * The y coordinate of the piece from its lower left corner. 
   */
  private int my_y;
  
  /**
   * The color of the abstract piece.
   */
  private Color my_color;
  
  
  /**
   * Constructs a tetris piece.
   * @param the_x the x coordinate the piece is to be placed in.
   * @param the_y the y coordinate the piece is to be placed in.
   * @param the_rotation the initial rotation of the piece.
   * @param the_color the color to assign the piece.
   */
  public AbstractPiece(final int the_x, final int the_y, final int[][] the_rotation, final 
                       Color the_color)
  {
    my_x = the_x;
    my_y = the_y;     
    my_rotation = the_rotation.clone();
    my_color = the_color;
  }
  
  /**
   * Gets the color of the tetris piece.
   * @return the color of the tetris piece
   */
  public Color getColor()
  {
    return my_color;
  }

  /**
   * Sets the color of the tetris piece.
   * @param the_color the color to set the tetris piece to
   */
  public void setColor(final Color the_color)
  {
    my_color = the_color;
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public void moveLeft()
  {
    my_x = my_x - 1;
  }
  /**
   * {@inheritDoc}
   */
  @Override
  public void moveRight()
  {
    my_x = my_x + 1; 
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public void moveDown()
  {
    my_y = my_y + 1;
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public int getX()
  {
    return my_x;
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public int getY()
  {
    return my_y;
  }
  
  /**
   * Gets the current rotation of the tetris piece.  
   * @return the 2 dimensional integer array that represents the tetris piece rotation
   */
  public int[][] getRotation()
  {
    return my_rotation.clone();
  }
  


}
